package routes

import (
	"net/http"

	"codeberg.org/vnpower/pixivfe/v2/audit"
	"codeberg.org/vnpower/pixivfe/v2/core"
	"codeberg.org/vnpower/pixivfe/v2/server/template"
)

func DiscoveryPage(auditor *audit.Auditor, w http.ResponseWriter, r *http.Request) error {
	mode := GetQueryParam(r, "mode", "safe")

	works, err := core.GetDiscoveryArtwork(auditor, r, mode)
	if err != nil {
		return err
	}

	urlc := template.PartialURL{
		Path:  "discovery",
		Query: map[string]string{"mode": mode},
	}

	return RenderHTML(w, r, Data_discovery{
		Artworks: works,
		Title:    "Discovery",
		Queries:  urlc,
	})
}

func NovelDiscoveryPage(auditor *audit.Auditor, w http.ResponseWriter, r *http.Request) error {
	mode := GetQueryParam(r, "mode", "safe")

	works, err := core.GetDiscoveryNovels(auditor, r, mode)
	if err != nil {
		return err
	}

	urlc := template.PartialURL{
		Path:  "discovery/novel",
		Query: map[string]string{"mode": mode},
	}

	return RenderHTML(w, r, Data_novelDiscovery{
		Novels:  works,
		Title:   "Discovery",
		Queries: urlc,
	})
}

func UserDiscoveryPage(auditor *audit.Auditor, w http.ResponseWriter, r *http.Request) error {
	users, err := core.GetDiscoveryUsers(auditor, r)
	if err != nil {
		return err
	}

	urlc := template.PartialURL{
		Path:  "discovery/users",
		Query: map[string]string{},
	}

	return RenderHTML(w, r, Data_userDiscovery{
		Users:   users,
		Title:   "Discovery",
		Queries: urlc,
	})
}
